#define _CRT_SECURE_NO_WARNINGS
#include"Stack.h"
void STInit(ST* ps)
{
	assert(ps);
	ps->a = NULL;

	ps->top = ps->capacity = 0;
	
}
void STDestroy(ST* ps)
{
	assert(ps);
	free(ps->a);
	ps->top = ps->capacity = 0;
}
void STPush(ST* ps, TypeDataST x)
{
	if (ps->top = ps->capacity)
	{
		int newcapacity = ps->capacity == 0 ? 4 : 2 * ps->capacity;
		TypeDataST* tmp = (TypeDataST*)realloc(ps->a, newcapacity * sizeof(TypeDataST));

		if (tmp == NULL)
		{
			perror("realloc fail");
			return;
		}


		ps->capacity = newcapacity;
		ps->a = tmp;

	}
	ps->a[ps->top] = x;
	ps->top++;
}

void STPop(ST* ps)
{
	assert(ps);
	assert(ps->top > 0);
	ps->top--;

}

int STSize(ST* ps)
{
	assert(ps);
	return ps->top;
}